﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
//using TracerX;
using System.Reflection;
using System.Diagnostics;

namespace DS2171Utils
{
   public static class TheLogger
    {
       //private static TheLogger m_TheLogger = new TheLogger() ;
       private static object _lockObj = new Object();
       static StackTrace _stackTrace = new StackTrace();
       static StackFrame _stackFrame = null;
       static Type _tipoEventinET = typeof(TraceEventType);
       static string _methodFullName = string.Empty;
       static MethodBase _metodo = null;


       //public static Logger LoggerMainApp = null;
       //public static Logger LoggerControls = null;
            
       
       //static  TheLogger()
       //{        
       //    Logger.ThreadName = "XTrace_Logger";
       //    Logger.BinaryFileLogging.Directory = Environment.GetFolderPath(
       //        Environment.SpecialFolder.MyDocuments);// Environment.CurrentDirectory;

       //    TracerX.Logger.BinaryFileLogging.Use_00 = true;
       //    TracerX.Logger.BinaryFileLogging.MaxSizeMb = 30;
       //    TracerX.Logger.BinaryFileLogging.FullFilePolicy = FullFilePolicy.CloseAndReopen; 

       //    LoggerMainApp = Logger.GetLogger("MainApp");

       //    LoggerControls = Logger.GetLogger("Controls");

       //    Logger.BinaryFileLogging.Open();           
       //}

       //public static Logger getNamedLogger(string pName)
       //{
       //    return Logger.GetLogger(pName);           
       //}//fM


       public static void loggaNet(string pMessage,TraceEventType pTipo)
       {
           lock (_lockObj)
           {

               _stackTrace = new StackTrace(); 
               // get calling method name

               _stackFrame = _stackTrace.GetFrame(1);

               _metodo = _stackFrame.GetMethod();
               _methodFullName = _metodo.DeclaringType.ToString() + _metodo.Name;//.Name;
             
               //var me = MethodBase.GetCurrentMethod();
               //var ass = me.DeclaringType.Name;
               //var assName = System.Reflection.Assembly.GetExecutingAssembly().GetName().Name;

               System.Diagnostics.Trace.WriteLine("In "+  pMessage, Enum.GetName(_tipoEventinET, pTipo));
               _metodo = null; 
               _stackTrace = null;
               
             
           }
       }


    }//fC
}
